﻿<UserControl x:Class="XamlHelpmeet.UI.Editors.DynamicFormTextBoxEditor"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:cvtrs="clr-namespace:XamlHelpmeet.UI.Converters"
             xmlns:local="XamlHelpmeet.UI.Editors"
             xmlns:rules="clr-namespace:XamlHelpmeet.UI.ValidationRules"
             Unloaded="DynamicFormTextBoxEditor_Unloaded">
    <UserControl.Resources>
        <Style TargetType="{x:Type TextBlock}">
            <Setter Property="HorizontalAlignment" Value="Left" />
            <Setter Property="VerticalAlignment" Value="Center" />
        </Style>

        <cvtrs:BindingModeEnumConverter x:Key="bindingModeEnumConverter" />

    </UserControl.Resources>

    <StackPanel>

        <DockPanel Margin="3">
            <Grid DockPanel.Dock="Right">
                <ComboBox x:Name="cboStringFormat"
                          MaxWidth="117"
                          Focusable="False"
                          IsSynchronizedWithCurrentItem="True"
                          Loaded="cboStringFormat_Loaded"
                          SelectedValuePath="StringFormat"
                          SelectionChanged="cboStringFormat_SelectionChanged">

                    <ComboBox.GroupStyle>
                        <GroupStyle>
                            <GroupStyle.HeaderTemplate>
                                <DataTemplate>
                                    <TextBlock Margin="0,5,0,0"
                                               Background="AntiqueWhite"
                                               FontWeight="Bold"
                                               Padding="2,0,0,0"
                                               Text="{Binding Path=Name}" />
                                </DataTemplate>
                            </GroupStyle.HeaderTemplate>
                        </GroupStyle>
                    </ComboBox.GroupStyle>
                </ComboBox>
                <TextBox Width="100"
                         Margin="0,0,17,0"
                         VerticalAlignment="Top"
                         TabIndex="2"
                         Text="{Binding Path=StringFormat,
                                        Mode=TwoWay,
                                        UpdateSourceTrigger=PropertyChanged}" />
            </Grid>
            <TextBlock Margin="0,0,10,0"
                       DockPanel.Dock="Right"
                       Text="Format" />
            <TextBlock Width="40" Text="Label" />
            <TextBox Width="125"
                     HorizontalAlignment="Left"
                     TabIndex="1"
                     Text="{Binding Path=AssociatedLabel,
                                    Mode=TwoWay}" />
        </DockPanel>

        <DockPanel Margin="3">
            <TextBox Width="50"
                     VerticalAlignment="Top"
                     DockPanel.Dock="Right"
                     TabIndex="4">
                <TextBox.Text>
                    <Binding Mode="TwoWay"
                             Path="Width"
                             UpdateSourceTrigger="LostFocus"
                             ValidatesOnDataErrors="True"
                             ValidatesOnExceptions="True">
                        <Binding.ValidationRules>
                            <rules:PositiveIntegerValidationRule />
                        </Binding.ValidationRules>
                    </Binding>
                </TextBox.Text>
            </TextBox>
            <TextBlock Margin="15,0,5,0"
                       HorizontalAlignment="Left"
                       DockPanel.Dock="Right"
                       Text="Width" />
            <TextBox Width="50"
                     VerticalAlignment="Top"
                     DockPanel.Dock="Right"
                     TabIndex="3">
                <TextBox.Text>
                    <Binding Mode="TwoWay"
                             Path="MaximumLength"
                             StringFormat="{}{0:D}"
                             TargetNullValue=""
                             UpdateSourceTrigger="LostFocus"
                             ValidatesOnDataErrors="True"
                             ValidatesOnExceptions="True">
                        <Binding.ValidationRules>
                            <rules:PositiveIntegerValidationRule />
                        </Binding.ValidationRules>
                    </Binding>
                </TextBox.Text>
            </TextBox>
            <TextBlock Margin="10,0,5,0"
                       HorizontalAlignment="Left"
                       DockPanel.Dock="Right"
                       Text="Max Length" />
            <TextBlock Width="40" Text="Mode" />
            <ComboBox Width="Auto"
                      HorizontalAlignment="Left"
                      Focusable="False"
                      FontSize="10"
                      IsSynchronizedWithCurrentItem="True"
                      Loaded="cboBindingMode_Loaded"
                      SelectedValue="{Binding Path=BindingMode,
                                              Mode=TwoWay,
                                              Converter={StaticResource bindingModeEnumConverter}}" />
        </DockPanel>

    </StackPanel>

</UserControl>
